// Sikkerhed.h: interface for the CSikkerhed class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SIKKERHED_H__49292E6B_00DE_4457_B406_30800E1FC032__INCLUDED_)
#define AFX_SIKKERHED_H__49292E6B_00DE_4457_B406_30800E1FC032__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <wincrypt.h>
#include <cstdlib>
//#include <boost/regex.hpp>
#include <string>
#include <iostream>

//using namespace boost;

extern const char EBAS_STANDARD[255];
extern const char EBAS_FAKTURA[255];
extern const char EBAS_EKSAMEN[255];
extern const char EBAS_INTERNET[255];
extern const char EBAS_TRIAL[255];

class CSikkerhed  
{
public:
	static CSikkerhed * GetInstance() {
		if (NULL == _singleton)
			_singleton = new CSikkerhed;
		return _singleton;
	}
	bstr_t Kryptering(const char * clearText);
	bstr_t VerificerBruger(bstr_t bruger, bstr_t kode, long adminOption);
	bstr_t MakeNewPassword(bstr_t bruger = bstr_t(""));
	bool VerificerLicens(bstr_t type);
	bool MakeTrialLicens(bstr_t navn);
	bool SkiftKode(bstr_t bruger, bstr_t gammel, bstr_t ny);
	bool HentLicensInfo(bstr_t * til, bstr_t * nummer, bstr_t * type, bstr_t * slut);
	bool GemLicensInfo(bstr_t til, bstr_t nummer, bstr_t slut, long type);
	bool HentAlleLicenser(_variant_t * licenser);
	bool NulstilAdgangskode(bstr_t brugernavn);
protected:
	CSikkerhed();
	virtual ~CSikkerhed();
	int ValidName(const char* text, std::string* msg);
	bool IsPasswordComplex(const char* text, std::string* msg);

	HCRYPTPROV hProv;
	void GenerateRandom(void *lpGood, DWORD cbGood)
	{
		CryptGenRandom(hProv, cbGood, reinterpret_cast<LPBYTE>(lpGood));
	}
private:
	static CSikkerhed * _singleton;

};

#endif // !defined(AFX_SIKKERHED_H__49292E6B_00DE_4457_B406_30800E1FC032__INCLUDED_)
